/******/ (() => { // webpackBootstrap
/******/ 	var __webpack_modules__ = ({

/***/ 651:
/***/ (() => {

(() => {
  if (self.Promise.prototype.finally) return;
  /**
  @method
  @param {Function}
  @return {Promise} initial */

  self.Promise.prototype.finally = function (onFinally) {
    // eslint-disable-line no-extend-native
    this.then(onFinally, onFinally);
    return this;
  };
})();

/***/ })

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
(() => {
"use strict";

// EXTERNAL MODULE: ./src/polyfills/Promise.prototype.finally.js
var Promise_prototype_finally = __webpack_require__(651);
;// CONCATENATED MODULE: ./src/general/tools/createElement.ts
/* global TreeElement, TreeTextNode */
const possibleAttributes = Object.freeze(['autocomplete', 'colspan', 'height', 'href', 'name', 'rowspan', 'src', 'target', 'type', 'width']);
/** @function */

let typescriptConverter = preObject => Object.assign({}, preObject, // @ts-ignore
{
  'type': typeof preObject.tag === 'string' ? 'element' : 'node'
});
/** Self-looped function to create elements tree
@function */


const createElement = (preObject, classModification = className => className) => {
  let object = typescriptConverter(preObject); // Node case

  if (object.type === 'node') {
    if (typeof object.text !== 'string') {
      throw new Error('createElement called without text property');
    }

    return document.createTextNode(object.text);
  } // Element case


  const {
    attributes,
    tag
  } = object;
  let element = document.createElement(tag);

  if (object.class) {
    let className = classModification(object.class);
    element.setAttribute('class', className);
  }

  if (object.style) element.setAttribute('style', object.style);

  if (attributes) {
    for (const [attribute, value] of Object.entries(attributes)) {
      const incompatibleAttributes = !possibleAttributes.includes(attribute) && !attribute.startsWith('data-');
      if (incompatibleAttributes) continue;
      if (attribute === 'src' && tag !== 'img') continue;
      element.setAttribute(attribute, value);
    }
  }

  if (object.node) object.node(element);
  if (object.text) element.textContent = object.text;

  if (object.children) {
    const children = object.children.map(child => createElement(child, classModification));
    children.forEach(child => {
      element.appendChild(child);
    });
  }

  return element;
};

/* harmony default export */ const tools_createElement = (createElement);
;// CONCATENATED MODULE: ./src/bg/contentScripts/notification/notification.css
/* harmony default export */ const notification = ("._Notification{\n  position: fixed;\n  bottom: 30px;\n\tright: 30px;\n  z-index: 44444444;\n  font-size: 14px;\n  line-height: 1.4;\n\tfont-family: tahoma, arial, sans-serif;\n}\n._Notification,\n._Notification *{\n  margin: 0;\n  padding: 0;\n}\n\n._Notification_Small,\n._Notification_Big{\n  display: none;\n}\n._Notification_Small{\n  width: 1px;\n\theight: 1px;\n\tborder-radius: 50%;\n\tbackground-color: #FFF;\n\tbox-shadow: 0 2px 7px rgba(0,0,0,.2);\n\ttransition: opacity .3s;\n  cursor: pointer;\n\tdisplay: none;\n\toverflow: hidden;\n\topacity: 0;\n}\n._Notification_Small:hover {\n\topacity: 1;\n}\n\n._Notification_Small:before,\n._Notification_Small:after{\n  content: ' ';\n  display:block;\n}\n._Notification_Small:before{\n  position: absolute;\n  left: 8px;\n  top: 8px;\n  width: 32px;\n  overflow:hidden;font-size:0;text-indent:-9999px;height:0;padding-top:32px;\n  box-sizing: content-box;\n  background: url(\"\");\n}\n._Notification_Small:after{\n  position: absolute;\n\tright: 2px;\n\ttop: 2px;\n\twidth: 10px;\n\toverflow:hidden;font-size:0;text-indent:-9999px;height:0;padding-top:10px;\n  box-sizing: content-box;\n\tbackground-color: #993B3B;\n\tborder-radius: 50%;\n}\n\n._Notification_Big{}\n._Notification_Big_In{\n  background-color: #FFF;\n\tcolor: #494B4D;\n\tbox-shadow: 0 5px 15px rgba(0,0,0,.15);\n\tborder-radius: 4px;\n\twidth: 340px;\n}\n\n._Notification_Big_In::before {\n  content: ' ';\n  display: block;\n\tborder-radius: 4px 4px 0 0;\n\tposition: relative;\n\toverflow:hidden;font-size:0;text-indent:-9999px;height:0;\n\tpadding-top:54px;\n  box-sizing: content-box;\n\tbackground: #1C304E url('') no-repeat center center;\n}\n\n._Notification_Big_In_In {\n\tpadding: 25px 30px 28px;\n\ttext-align: center;\n}\n\n._Notification_Big_Title{\n\tmargin-bottom: 11px;\n\tfont-size: 18px;\n\tfont-weight: 600;\n\tcolor: #3B9946;\n\ttext-align: center;\n}\n\n._Notification_Big_Text{\n\tfont-size: 14px;\n\tline-height: 22px;\n\ttext-align: center;\n  padding-bottom: 20px;\n}\n\na._Notification_Big_Button{\n\tborder-radius: 3px;\n  position: relative;\n\tdisplay: table;\n  height: 40px;\n  width: 100%;\n\tfont-size: 14px;\n\tbackground-color: #3B9946;\n\ttext-align: center;\n\ttext-decoration: none;\n\tcolor: #fff;\n\ttransition: background .3s;\n}\na._Notification_Big_Button:hover{\n\tbackground: #308139;\n  color: #fff;\n\ttext-decoration: none;\n}\na._Notification_Big_Button_long{\n  height: 48px;\n}\n._Notification_Big_Button_In{\n  display: table-cell;\n  vertical-align: middle;\n  padding: 0px 15px;\n}\n._Notification_Big_Button_Name{\n  line-height: 20px;\n}\n._Notification_Big_Button_Name_uppercase{\n  text-transform: uppercase;\n  font-weight: bold;\n}\n._Notification_Big_Button_Price{\n  display: block;\n  font-size: 12px;\n}\n._Notification_Big_Button_Price_Value{\n  font-weight: bold;\n}\n._Notification_Big_Button_Price_OldValue{\n  text-decoration: line-through;\n  color: #9aca9f;\n  margin-left: 3px;\n}\n\n._Notification_Big_Button_Discount{\n  display: block;\n  position: absolute;\n  top: 0;\n  bottom: 0;\n  right: 8px;\n}\n._Notification_Big_Button_Discount_In{\n  width: 36px;\n  height: 36px;\n  background-repeat: no-repeat;\n  background-position: 0 0;\n  background-image: url(\"\");\n  background-size: 100% 100%;\n  display: table;\n  position: absolute;\n  right: 0;\n  top: calc(50% - 36px / 2);\n}\n._Notification_Big_Button_Discount_In_In{\n  display: table-cell;\n  vertical-align: middle;\n}\n._Notification_Big_Button_Discount_Minus{\n  display: inline-block;\n  vertical-align: middle;\n  font-size: 10px;\n  font-weight: bold;\n}\n._Notification_Big_Button_Discount_Value{\n  display: inline-block;\n  vertical-align: middle;\n  font-size: 14px;\n  font-weight: bold;\n}\n._Notification_Big_Button_Discount_Percent{\n  display: inline-block;\n  vertical-align: middle;\n  font-size: 8px;\n  font-weight: bold;\n}\n\n._Notification_Later{\n  padding-top: 15px;\n  text-align: center;\n}\n._Notification_Later_In{\n  cursor: pointer;\n  color: #1C304E;\n  text-decoration: underline;\n}\n._Notification_Later_In:hover{\n  color: #1C304E;\n  text-decoration: none;\n}\n\n._Notification._Notification_stSmall ._Notification_Small{\n\tdisplay: none!important;\n\twidth: 48px;\n\theight: 48px;\n\topacity: .5;\n}\n._Notification._Notification_stBig ._Notification_Big{\n  display: block!important;\n}\n");
;// CONCATENATED MODULE: ./src/general/tools/insertStyle.ts
/** Add text style in page
@function
@param css - like '.class{ display: block; }' */
/* harmony default export */ const insertStyle = (css => {
  let style
  /*: HTMLStyleElement*/
  = document.createElement('style');
  style.type = 'text/css';
  style.appendChild(document.createTextNode(css));
  document.head.appendChild(style);
});
;// CONCATENATED MODULE: ./src/contentScripts/notification.ts
/* global TreeElement */

 // @ts-ignore



const originalCss = notification; // TS crap

const minClassLength = (() => {
  let lengths = originalCss.split('{').slice(0, -1).flatMap((part, index) => {
    part = part.trim();
    if (index) part = part.split('}')[1];
    return part.split(',').map(item => item.trim().replace(/^\./g, '').length);
  });
  return Math.min.apply(Math, lengths);
})(); // Class modification parameter


const modifierOptions = {
  'offset': 1 + Math.floor(Math.random() * (minClassLength - 1)),
  'value': Math.floor(Math.random() * 999999)
};
/** @function */

const modifier = className => {
  const left
  /*: string*/
  = className.slice(0, modifierOptions.offset);
  const right
  /*: string*/
  = className.slice(modifierOptions.offset);
  return left + modifierOptions.value + right;
};
/** @function */


const classModification = className => className.split(' ').map(part => modifier(part)).join(' ');

const css = originalCss.split('}').slice(0, -1).map(part => {
  let [selectors, rules]
  /*: string[]*/
  = // eslint-disable-line standard/array-bracket-even-spacing
  part.split('{').map(item => item.trim());
  rules = '{' + rules + '}';
  selectors = selectors.split(',').map(selector => selector.trim().replace(/\.([_a-zA-Z]+)/g, (match, className) => '.' + modifier(className))).join(',');
  return selectors + rules;
}).join('');
/** @function */

const sendMessage = message => {
  if (typeof browser !== 'undefined') {
    return browser.runtime.sendMessage(message);
  }

  return new Promise(resolve => {
    chrome.runtime.sendMessage(message, resolve);
  });
}; // User's language


const language
/*: string*/
= navigator.language.slice(0, 2).toLowerCase(); // Main execution flow

(async () => {
  /** Intitial call to get popup status + translation
  (When page fully loaded + message received) */
  let {
    html,
    size
  } = await new Promise(async resolve => {
    const data = await sendMessage({
      language,
      'type': 'notification:request:initial',
      'url': location.href
    });
    if (data === null || data === void 0 ? void 0 : data.show) resolve(data);
  }); // Inserting styles in <head>

  insertStyle(css);

  let elements = (() => {
    let elements = {};
    let structure = {
      'tag': 'div',
      'class': '_Notification ' + (size === 'small' ? '_Notification_stSmall' : '_Notification_stBig'),
      'children': [{
        'tag': 'div',
        'class': '_Notification_Small',
        'node': node => {
          elements.makeBig = node;
        }
      }, {
        'tag': 'div',
        'class': '_Notification_Big',
        'children': [html]
      }]
    };
    elements.parent = tools_createElement(structure, classModification)
    /*: any*/
    ;
    elements.makeSmall = Array.from(elements.parent.querySelectorAll('[data-click="close"]'));
    return elements;
  })();
  /** @function */


  const setVisibility = visible => {
    sendMessage({
      'type': 'notification:request:setVisibility',
      visible
    });

    if (visible) {
      elements.parent.classList.add(modifier('_Notification_stBig'));
      elements.parent.classList.remove(modifier('_Notification_stSmall'));
    } else {
      elements.parent.classList.remove(modifier('_Notification_stBig'));
      elements.parent.classList.add(modifier('_Notification_stSmall'));
    }
  };

  elements.makeBig.addEventListener('click', () => {
    setVisibility(true);
  });
  elements.makeSmall.forEach(element => {
    element.addEventListener('click', () => {
      setVisibility(false);
    });
  });
  elements.parent.querySelectorAll('a').forEach(link => {
    link.addEventListener('click', async event => {
      event.preventDefault();
      sendMessage({
        'type': 'notification:request:click',
        'url': location.href
      });
      await new Promise(resolve => {
        setTimeout(resolve, 50);
      });
      self.open(link.href);
    });
  }); // Inserting into actual DOM with delay

  setTimeout(() => {
    document.body.append(elements.parent); // Wait for actual showing

    if (size !== 'big') return;
    const rect = elements.parent.getClientRects()[0];
    if (!rect.width || !rect.height) return;
    sendMessage({
      'type': 'notification:request:popupShow',
      'url': location.href
    });
  }, 10 * 1000); // Ping to check all is OK

  /** @function */

  const ping = async () => {
    try {
      await new Promise((resolve, reject) => {
        try {
          sendMessage({
            'type': 'notification:ping'
          }).then(state => {
            if (state === 'ok') resolve();
          });
          setTimeout(() => {
            reject(new Error('Ping timeout reached'));
          }, 3000);
        } catch (error) {
          reject(error);
        }
      });
      setTimeout(ping, 4000);
    } catch (x) {
      elements.parent.remove();
    }
  };

  ping();
})();
})();

/******/ })()
;